﻿using UnityEngine;
using System.Collections;
using System.Text;
using System.IO;  

public class DoorHandler : MonoBehaviour {


	//Private Variables
	private string subPath ="GameFiles";
	private string txtFileName = "stats.txt";
	
	// Update is called once per frame
	void Update () {

	}

	void OnCollisionEnter2D(Collision2D target){
		print("Collision With Door");
		if(target.gameObject.tag.Equals("Player")){
			int currentLevel = int.Parse(GameStatus.currentLevel);
			int nextLevel = currentLevel + 1;

			string readFromStatsFile = File.ReadAllText(subPath + "/" + txtFileName);
			readFromStatsFile = readFromStatsFile.Replace(currentLevel + "", nextLevel + "");
			File.WriteAllText(subPath + "/" + txtFileName, readFromStatsFile);
			
			print(readFromStatsFile);
			Application.LoadLevel("Level " + nextLevel + " - " + GameStatus.difficulty);	
		}
	}
}
